package com.jiantong.lawEnforcing.impl.dao;

import com.google.common.collect.Maps;
import com.jiantong.lawEnforcing.model.CasesInformation;
import io.terminus.common.model.Paging;
import io.terminus.common.mysql.dao.MyBatisDao;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 案件信息
 * Created by mz03 on 2017/9/13.
 */
@Repository
public class CasesInformationDao extends MyBatisDao<CasesInformation>{


    /**
     * 根据一组条件查询 状态传List<Integer>
     * @param offset
     * @param limit
     * @param criteria
     * @return
     */
    public Paging<CasesInformation> pagingList(Integer offset, Integer limit, Map<String, Object> criteria) {
        if(criteria == null) {
            criteria = Maps.newHashMap();
        }

        Long total = getSqlSession().selectOne(sqlId("countList"), criteria);
        if(total <= 0L) {
            return new Paging<>(0L, Collections.emptyList());
        } else {
            criteria.put("offset", offset);
            criteria.put("limit", limit);
            List<CasesInformation> datas = getSqlSession().selectList(sqlId("pagingList"), criteria);
            return new Paging<>(total, datas);
        }


    }


    public List<Map<String,Integer>> countByCasesSource() {

        return getSqlSession().selectList(this.sqlId("countByCasesSource"));
    }


    public List<Map<String,Integer>> countByCasesType() {

        return getSqlSession().selectList(this.sqlId("countByCasesType"));
    }

        /* Mapper.xml 中的写法
           <if test="status_list != null">
                status IN
                <foreach collection="status_list" open="(" separator="," close=")" item="status">
                  #{status}
                </foreach>
            </if>
         */
}
